package com.xinkao.example.util.easyexcel.converter;


import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.CellData;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.property.ExcelContentProperty;

/**
 * easyexcel 数据格式转换器
 * @Author lililiang
 * @Date 2021/6/18 8:53
 */
public class SexConverter implements Converter<Integer> {


    //在java中类型
    @Override
    public Class supportJavaTypeKey() {
        return Integer.class;
    }
    // 在excel中的类型
    @Override
    public CellDataTypeEnum supportExcelTypeKey() {
        return CellDataTypeEnum.STRING;
    }

    //将excel的数据类型转为java数据类型
    @Override
    public Integer convertToJavaData(CellData cellData, ExcelContentProperty excelContentProperty, GlobalConfiguration globalConfiguration) {
        String stringValue = cellData.getStringValue();
        if (stringValue == null) {
            return -1;
        }
        switch (stringValue){
            case "男" : return 1;
            case "女" : return 2;
            default: return 3;
        }
    }
    //将java的数据类型转为excel数据类型
    @Override
    public CellData convertToExcelData(Integer s, ExcelContentProperty excelContentProperty, GlobalConfiguration globalConfiguration) {
        switch (s){
            case 1 : return new CellData("男");
            case 2 : return new CellData("女");
            default: return new CellData("");
        }
    }


}
